/**
 * @author     Gabor Greif <ggreif@gmail.com>
 * @copyright  2009-2010 Gabor Greif
 * @license    http://www.opensource.org/licenses/mit-license.php  MIT License
 * @version    Release: 0.0
 */

#ifndef micker_CHEX_hpp
#define micker_CHEX_hpp

#include "Command.hpp"

namespace micker {

struct Hex : Comm<>
{
    Hex(bool dir = false)
    : Comm<>(dir
             ? CommandProc(ArgumentsMismatch<1>::proc<void, toHex>)
             : CommandProc(ArgumentsMismatch<1>::proc<void, toDec>))
    {}

    static std::string toDec(const std::string& arg)
    {
        unsigned long val(0);
        sscanf(arg.c_str(), "%lx", &val);
        char displ[30];
        sprintf(displ, "%lu", val);
        return displ;
    }

    static std::string toHex(const std::string& arg)
    {
        unsigned long val(0);
        sscanf(arg.c_str(), "%lu", &val);
        char displ[30];
        sprintf(displ, "%lx", val);
        return displ;
    }
};

} // namespace micker

#endif // micker_CHEX_hpp
